---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
-- Quest Dialog File: This file decides which dialog to display based off of given missions      --
-- from an Entity                                                                                --
--																								 --
--	Author: Tony Sparks																			 --
--	Date: 1-02-07                                                                                --
---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------

console.Exec( "echo Loading a mission check file..." );

-- Function to discard the mission
function GiveReward( missionName )
--{
	dofile( missionName .. "_reward.lua" );
	player.SetMissionStatus( missionName, REWARDED );
--}
end

--[[---------------------------------------------------------------
--		Decides which dialog to play for the NPC
--		If a mission has been completed, it will run the
--		associated reward script.
--]]---------------------------------------------------------------
function GiveMission( mission_names )
--{
	--
	-- Test Missions --
	local i = 1;
	dialog:Clear();
	
	while (i <= #mission_names) 
	do

		-- console.Exec( "echo Mission " .. mission_names[i] .. " is " .. player.CheckMissionStatus(mission_names[i]) );
		-- If this mission has not been assigned, assign it
 		-- and pick the proper dialog to display
		if (not player.HasMission(mission_names[i]) )
		then
			-- Give the Player a new mission
			dialog.Create();
			dialog.LoadDialog( mission_names[i] .. ".dialog" );
			break;

		-- Mission is not done yet!
		elseif ( player.CheckMissionStatus(mission_names[i]) == INPROGRESS )
		then
			-- Display the inprogress dialog
			dialog.Create();
			dialog.LoadDialog( mission_names[i] .."_inprogress.dialog" );
			break;
			
		-- Mission has been completed, now give the player a reward!!!
		elseif ( player.CheckMissionStatus(mission_names[i]) == COMPLETED )
		then
			-- Give the player a reward
			GiveReward( mission_names[i] );		
			
		-- the Mission was a failer, most likely ask him to do it again
		elseif ( player.CheckMissionStatus(mission_names[i]) == FAILED )
		then
			-- Display the failed
			dialog.Create();
			dialog.LoadDialog( mission_names[i] .."_failed.dialog" );
			break;
		end

		-- Mission is marked as REWARDED so we skip it
		i= i+1;
		
	end
--}
end